package cn.iocoder.yudao.module.team.controller.admin.hotel;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.team.controller.admin.hotel.vo.*;
import cn.iocoder.yudao.module.team.dal.dataobject.hotel.HotelDO;
import cn.iocoder.yudao.module.team.service.hotel.HotelService;

@Tag(name = "管理后台 - 团队—酒店管理")
@RestController
@RequestMapping("/team/hotel")
@Validated
public class HotelController {

    @Resource
    private HotelService hotelService;

    @PostMapping("/create")
    @Operation(summary = "创建团队—酒店管理")
    @PreAuthorize("@ss.hasPermission('team:hotel:create')")
    public CommonResult<Integer> createHotel(@Valid @RequestBody HotelSaveReqVO createReqVO) {
        return success(hotelService.createHotel(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新团队—酒店管理")
    @PreAuthorize("@ss.hasPermission('team:hotel:update')")
    public CommonResult<Boolean> updateHotel(@Valid @RequestBody HotelSaveReqVO updateReqVO) {
        hotelService.updateHotel(updateReqVO);
        return success(true);
    }
    @PutMapping("/updateBatch")
    @Operation(summary = "批量更新团队—酒店管理")
    @PreAuthorize("@ss.hasPermission('team:hotel:update')")
    public CommonResult<Boolean> updateBatchHotel(@Valid @RequestBody List<HotelDO>  updateReqVO) {
        hotelService.updateBatchHotel(updateReqVO);
        return success(true);
    }
    @DeleteMapping("/delete")
    @Operation(summary = "删除团队—酒店管理")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('team:hotel:delete')")
    public CommonResult<Boolean> deleteHotel(@RequestParam("id") Integer id) {
        hotelService.deleteHotel(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除团队—酒店管理")
                @PreAuthorize("@ss.hasPermission('team:hotel:delete')")
    public CommonResult<Boolean> deleteHotelList(@RequestParam("ids") List<Integer> ids) {
        hotelService.deleteHotelListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得团队—酒店管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('team:hotel:query')")
    public CommonResult<HotelRespVO> getHotel(@RequestParam("id") Integer id) {
        HotelDO hotel = hotelService.getHotel(id);
        return success(BeanUtils.toBean(hotel, HotelRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得团队—酒店管理分页")
    @PreAuthorize("@ss.hasPermission('team:hotel:query')")
    public CommonResult<PageResult<HotelRespVO>> getHotelPage(@Valid HotelPageReqVO pageReqVO) {
        PageResult<HotelDO> pageResult = hotelService.getHotelPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, HotelRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出团队—酒店管理 Excel")
    @PreAuthorize("@ss.hasPermission('team:hotel:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportHotelExcel(@Valid HotelPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<HotelDO> list = hotelService.getHotelPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "团队—酒店管理.xls", "数据", HotelRespVO.class,
                        BeanUtils.toBean(list, HotelRespVO.class));
    }

}